<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Arthas," />










<meta name="description" content="Arthas进阶使用，介绍每个命令的详细使用方法">
<meta name="keywords" content="Arthas">
<meta property="og:type" content="article">
<meta property="og:title" content="Arthas进阶使用">
<meta property="og:url" content="http://yoursite.com/2018/12/11/Arthas进阶使用/Arthas进阶使用/index.html">
<meta property="og:site_name" content="程序员乌托邦">
<meta property="og:description" content="Arthas进阶使用，介绍每个命令的详细使用方法">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-12-11T07:30:29.265Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Arthas进阶使用">
<meta name="twitter:description" content="Arthas进阶使用，介绍每个命令的详细使用方法">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/12/11/Arthas进阶使用/Arthas进阶使用/"/>





  <title>Arthas进阶使用 | 程序员乌托邦</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">程序员乌托邦</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/12/11/Arthas进阶使用/Arthas进阶使用/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Wolf、Heart">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="程序员乌托邦">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Arthas进阶使用</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-12-11T15:26:25+08:00">
                2018-12-11
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Arthas/" itemprop="url" rel="index">
                    <span itemprop="name">Arthas</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="Arthas进阶使用，介绍每个命令的详细使用方法"><a href="#Arthas进阶使用，介绍每个命令的详细使用方法" class="headerlink" title="Arthas进阶使用，介绍每个命令的详细使用方法"></a>Arthas进阶使用，介绍每个命令的详细使用方法</h3><a id="more"></a>
<h1 id="一、基础命令"><a href="#一、基础命令" class="headerlink" title="一、基础命令"></a>一、基础命令</h1><ol>
<li>help 查看命令帮助信息</li>
<li>cls  清空当前屏幕区域</li>
<li>session 查看当前会话信息</li>
<li>version 查看当前arthas版本</li>
<li>history 查看输入的历史命令</li>
<li>quit 退出当前arthas客户端</li>
<li>shutdown 关闭arthas服务端，所有arthas客户端全部退出</li>
<li>keymap arthas快捷键列表及自定义快捷键</li>
<li>reset 重置增强类，将被 Arthas 增强过的类全部还原，Arthas 服务端关闭时会重置所有增强过的类</li>
</ol>
<h1 id="二、jvm相关"><a href="#二、jvm相关" class="headerlink" title="二、jvm相关"></a>二、jvm相关</h1><h2 id="dashboard"><a href="#dashboard" class="headerlink" title="dashboard"></a>dashboard</h2><p>当前系统的实时数据面板</p>
<h2 id="thread"><a href="#thread" class="headerlink" title="thread"></a>thread</h2><p>查看当前线程信息，查看线程堆栈<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">thread -n 3 显示前3个最忙的线程堆栈信息</span><br><span class="line">thread 显示所有的线程信息</span><br><span class="line">thread id 显示指定线程的堆栈信息</span><br><span class="line">thread -b 找出阻塞其它线程的线程信息，目前只支持synchronized的阻塞</span><br><span class="line">thread -i 1000 指定采样时间间隔，单位为ms</span><br></pre></td></tr></table></figure></p>
<p>模拟线程阻塞代码<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">public class Test &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        Thread thread1 = new Thread(new Task());</span><br><span class="line">        Thread thread2 = new Thread(new Task());</span><br><span class="line">        thread1.start();</span><br><span class="line">        thread2.start();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    static class Task implements Runnable &#123;</span><br><span class="line"></span><br><span class="line">        @Override</span><br><span class="line">        public void run() &#123;</span><br><span class="line">            synchronized (Test.class) &#123;</span><br><span class="line">                while (true) &#123;</span><br><span class="line">                    try &#123;</span><br><span class="line">                        Thread.sleep(1000);</span><br><span class="line">                    &#125; catch (InterruptedException e) &#123;</span><br><span class="line">                        e.printStackTrace();</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>通过thread -b找出阻塞其它线程的线程信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">$ thread -b</span><br><span class="line">&quot;Thread-0&quot; Id=13 TIMED_WAITING</span><br><span class="line">    at java.lang.Thread.sleep(Native Method)</span><br><span class="line">    at com.boot.example.Test$Task.run(Test.java:25)</span><br><span class="line">    -  locked java.lang.Class@1b40d5f0 &lt;---- but blocks 1 other threads!</span><br><span class="line">    at java.lang.Thread.run(Thread.java:748)</span><br></pre></td></tr></table></figure></p>
<h2 id="jvm"><a href="#jvm" class="headerlink" title="jvm"></a>jvm</h2><p>查看当前jvm信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">jvm</span><br></pre></td></tr></table></figure></p>
<h2 id="sysprop"><a href="#sysprop" class="headerlink" title="sysprop"></a>sysprop</h2><p>查看当前jvm的系统属性<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ sysprop java.version</span><br><span class="line">java.version=1.8.0_161</span><br></pre></td></tr></table></figure></p>
<h2 id="sysenv"><a href="#sysenv" class="headerlink" title="sysenv"></a>sysenv</h2><p>查看当前jvm的环境属性<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ sysenv M2_HOME</span><br><span class="line">M2_HOME=/Users/pengli/software/maven/apache-maven-3.5.3</span><br></pre></td></tr></table></figure></p>
<h2 id="getstatic"><a href="#getstatic" class="headerlink" title="getstatic"></a>getstatic</h2><p>查看一个类的静态属性</p>
<p>getstatic class_name field_name<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ getstatic com.boot.example.Test STR</span><br><span class="line">field: STR</span><br><span class="line">@String[test getstatic]</span><br><span class="line">Affect(row-cnt:1) cost in 8 ms.</span><br></pre></td></tr></table></figure></p>
<h2 id="ognl"><a href="#ognl" class="headerlink" title="ognl"></a>ognl</h2><p>查看类的静态属性<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ ognl &apos;@com.boot.example.Test@STR&apos;</span><br><span class="line">@String[test getstatic]</span><br></pre></td></tr></table></figure></p>
<p>给静态属性复制，并打印静态属性值<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ ognl &apos;#value1=@System@getProperty(&quot;java.home&quot;), #value2=@System@getProperty(&quot;java.runtime.name&quot;), &#123;#value1, #value2&#125;&apos;</span><br><span class="line">@ArrayList[</span><br><span class="line">    @String[/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre],</span><br><span class="line">    @String[Java(TM) SE Runtime Environment],</span><br><span class="line">]</span><br></pre></td></tr></table></figure></p>
<h2 id="sc"><a href="#sc" class="headerlink" title="sc"></a>sc</h2><p>查看jvm已加载的类信息</p>
<p>模糊搜索<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">sc com.boot.example.*</span><br><span class="line">com.boot.example.Test</span><br><span class="line">com.boot.example.Test$Task</span><br><span class="line">Affect(row-cnt:2) cost in 4 ms.</span><br></pre></td></tr></table></figure></p>
<p>查看当前类的详细信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">$ sc -d com.boot.example.Test</span><br><span class="line"> class-info        com.boot.example.Test</span><br><span class="line"> code-source       /Users/pengli/software/idea/workspace/boot-example/boot-example-start/target/classes/</span><br><span class="line"> name              com.boot.example.Test</span><br><span class="line"> isInterface       false</span><br><span class="line"> isAnnotation      false</span><br><span class="line"> isEnum            false</span><br><span class="line"> isAnonymousClass  false</span><br><span class="line"> isArray           false</span><br><span class="line"> isLocalClass      false</span><br><span class="line"> isMemberClass     false</span><br><span class="line"> isPrimitive       false</span><br><span class="line"> isSynthetic       false</span><br><span class="line"> simple-name       Test</span><br><span class="line"> modifier          public</span><br><span class="line"> annotation</span><br><span class="line"> interfaces</span><br><span class="line"> super-class       +-java.lang.Object</span><br><span class="line"> class-loader      +-sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">                     +-sun.misc.Launcher$ExtClassLoader@5d152595</span><br><span class="line"> classLoaderHash   18b4aac2</span><br><span class="line"></span><br><span class="line">Affect(row-cnt:1) cost in 17 ms.</span><br></pre></td></tr></table></figure></p>
<p>查看当前类的属性信息，需要集合-d和-f一起使用<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">$ sc -d -f com.boot.example.Test</span><br><span class="line"> class-info        com.boot.example.Test</span><br><span class="line"> code-source       /Users/pengli/software/idea/workspace/boot-example/boot-example-start/target/classes/</span><br><span class="line"> name              com.boot.example.Test</span><br><span class="line"> isInterface       false</span><br><span class="line"> isAnnotation      false</span><br><span class="line"> isEnum            false</span><br><span class="line"> isAnonymousClass  false</span><br><span class="line"> isArray           false</span><br><span class="line"> isLocalClass      false</span><br><span class="line"> isMemberClass     false</span><br><span class="line"> isPrimitive       false</span><br><span class="line"> isSynthetic       false</span><br><span class="line"> simple-name       Test</span><br><span class="line"> modifier          public</span><br><span class="line"> annotation</span><br><span class="line"> interfaces</span><br><span class="line"> super-class       +-java.lang.Object</span><br><span class="line"> class-loader      +-sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">                     +-sun.misc.Launcher$ExtClassLoader@20fc130a</span><br><span class="line"> classLoaderHash   18b4aac2</span><br><span class="line"> fields            modifierfinal,private,static</span><br><span class="line">                   type    java.lang.String</span><br><span class="line">                   name    STR</span><br><span class="line">                   value   test getstatic</span><br><span class="line"></span><br><span class="line">                   modifierprivate</span><br><span class="line">                   type    java.lang.Integer</span><br><span class="line">                   name    number</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">Affect(row-cnt:1) cost in 21 ms.</span><br></pre></td></tr></table></figure></p>
<h2 id="sc-1"><a href="#sc-1" class="headerlink" title="sc"></a>sc</h2><p>查看已加载类的方法信息</p>
<p>示例代码<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">public class Test &#123;</span><br><span class="line"></span><br><span class="line">    private static final String STR = &quot;test getstatic&quot;;</span><br><span class="line"></span><br><span class="line">    private Integer number = 0;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        Thread thread1 = new Thread(new Task());</span><br><span class="line">        Thread thread2 = new Thread(new Task());</span><br><span class="line">        thread1.start();</span><br><span class="line">        thread2.start();</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    public void test() &#123;</span><br><span class="line">        System.out.println(&quot;测试方法&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    static class Task implements Runnable &#123;</span><br><span class="line"></span><br><span class="line">        @Override</span><br><span class="line">        public void run() &#123;</span><br><span class="line">            synchronized (Test.class) &#123;</span><br><span class="line">                while (true) &#123;</span><br><span class="line">                    try &#123;</span><br><span class="line">                        Thread.sleep(1000);</span><br><span class="line">                    &#125; catch (InterruptedException e) &#123;</span><br><span class="line">                        e.printStackTrace();</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>查看当前了类的方法信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ sm com.boot.example.Test</span><br><span class="line">com.boot.example.Test-&gt;&lt;init&gt;</span><br><span class="line">com.boot.example.Test-&gt;main</span><br><span class="line">com.boot.example.Test-&gt;test</span><br><span class="line">Affect(row-cnt:3) cost in 10 ms.</span><br></pre></td></tr></table></figure></p>
<p>查看当前类方法的详细信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">sm -d com.boot.example.Test test</span><br><span class="line"> declaring-class  com.boot.example.Test</span><br><span class="line"> method-name      test</span><br><span class="line"> modifier         private</span><br><span class="line"> annotation</span><br><span class="line"> parameters</span><br><span class="line"> return           void</span><br><span class="line"> exceptions</span><br></pre></td></tr></table></figure></p>
<h2 id="dump"><a href="#dump" class="headerlink" title="dump"></a>dump</h2><p>导出已加载类的字节码信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ dump com.boot.example.Test</span><br><span class="line"> HASHCODE  CLASSLOADER                                    LOCATION</span><br><span class="line"> 18b4aac2  +-sun.misc.Launcher$AppClassLoader@18b4aac2    /Users/pengli/logs/arthas/classdump/sun.misc.Launcher$AppClassLoader-18b4aac2/com/boot/examp</span><br><span class="line">             +-sun.misc.Launcher$ExtClassLoader@6f9b7884  le/Test.class</span><br><span class="line">Affect(row-cnt:1) cost in 29 ms.</span><br></pre></td></tr></table></figure></p>
<p>可以在指定目录找到导出的字节码文件，这样可以很方便的查看到该类的相关信息，比如是否为最新的代码</p>
<h2 id="jad"><a href="#jad" class="headerlink" title="jad"></a>jad</h2><p>反编译已加载的类<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">$ jad com.boot.example.Test</span><br><span class="line"></span><br><span class="line">ClassLoader:</span><br><span class="line">+-sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">  +-sun.misc.Launcher$ExtClassLoader@46a131c</span><br><span class="line"></span><br><span class="line">Location:</span><br><span class="line">/Users/pengli/software/idea/workspace/boot-example/boot-example-start/target/classes/</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> * Decompiled with CFR 0_132.</span><br><span class="line"> */</span><br><span class="line">package com.boot.example;</span><br><span class="line"></span><br><span class="line">import java.io.PrintStream;</span><br><span class="line"></span><br><span class="line">public class Test &#123;</span><br><span class="line">    private static final String STR = &quot;test getstatic&quot;;</span><br><span class="line">    private Integer number = 0;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        Thread thread1 = new Thread(new Task());</span><br><span class="line">        Thread thread2 = new Thread(new Task());</span><br><span class="line">        thread1.start();</span><br><span class="line">        thread2.start();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private void test() &#123;</span><br><span class="line">        System.out.println(&quot;\u6d4b\u8bd5\u65b9\u6cd5&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void test1() &#123;</span><br><span class="line">        System.out.println(&quot;\u6d4b\u8bd5\u65b9\u6cd51&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    static class Task</span><br><span class="line">    implements Runnable &#123;</span><br><span class="line">        Task() &#123;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        @Override</span><br><span class="line">        public void run() &#123;</span><br><span class="line">            Class&lt;Test&gt; class_ = Test.class;</span><br><span class="line">            synchronized (Test.class) &#123;</span><br><span class="line">                do &#123;</span><br><span class="line">                    try &#123;</span><br><span class="line">                        do &#123;</span><br><span class="line">                            Thread.sleep(1000L);</span><br><span class="line">                        &#125; while (true);</span><br><span class="line">                    &#125;</span><br><span class="line">                    catch (InterruptedException e) &#123;</span><br><span class="line">                        e.printStackTrace();</span><br><span class="line">                        continue;</span><br><span class="line">                    &#125;</span><br><span class="line">                    break;</span><br><span class="line">                &#125; while (true);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">Affect(row-cnt:2) cost in 616 ms.</span><br></pre></td></tr></table></figure></p>
<p>反编译已加载的类方法<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">$ jad com.boot.example.Test test</span><br><span class="line"></span><br><span class="line">ClassLoader:</span><br><span class="line">+-sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">  +-sun.misc.Launcher$ExtClassLoader@46a131c</span><br><span class="line"></span><br><span class="line">Location:</span><br><span class="line">/Users/pengli/software/idea/workspace/boot-example/boot-example-start/target/classes/</span><br><span class="line"></span><br><span class="line">private void test() &#123;</span><br><span class="line">    System.out.println(&quot;\u6d4b\u8bd5\u65b9\u6cd5&quot;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">Affect(row-cnt:2) cost in 174 ms.</span><br></pre></td></tr></table></figure></p>
<p>反编译指定ClassLoader加载的类信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">$ jad com.boot.example.Test -c 18b4aac2(类加载器对应的hashcode)</span><br><span class="line"></span><br><span class="line">ClassLoader:</span><br><span class="line">+-sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">  +-sun.misc.Launcher$ExtClassLoader@46a131c</span><br><span class="line"></span><br><span class="line">Location:</span><br><span class="line">/Users/pengli/software/idea/workspace/boot-example/boot-example-start/target/classes/</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> * Decompiled with CFR 0_132.</span><br><span class="line"> */</span><br><span class="line">package com.boot.example;</span><br><span class="line"></span><br><span class="line">import java.io.PrintStream;</span><br><span class="line"></span><br><span class="line">public class Test &#123;</span><br><span class="line">    private static final String STR = &quot;test getstatic&quot;;</span><br><span class="line">    private Integer number = 0;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        Thread thread1 = new Thread(new Task());</span><br><span class="line">        Thread thread2 = new Thread(new Task());</span><br><span class="line">        thread1.start();</span><br><span class="line">        thread2.start();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private void test() &#123;</span><br><span class="line">        System.out.println(&quot;\u6d4b\u8bd5\u65b9\u6cd5&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void test1() &#123;</span><br><span class="line">        System.out.println(&quot;\u6d4b\u8bd5\u65b9\u6cd51&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    static class Task</span><br><span class="line">    implements Runnable &#123;</span><br><span class="line">        Task() &#123;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        @Override</span><br><span class="line">        public void run() &#123;</span><br><span class="line">            Class&lt;Test&gt; class_ = Test.class;</span><br><span class="line">            synchronized (Test.class) &#123;</span><br><span class="line">                do &#123;</span><br><span class="line">                    try &#123;</span><br><span class="line">                        do &#123;</span><br><span class="line">                            Thread.sleep(1000L);</span><br><span class="line">                        &#125; while (true);</span><br><span class="line">                    &#125;</span><br><span class="line">                    catch (InterruptedException e) &#123;</span><br><span class="line">                        e.printStackTrace();</span><br><span class="line">                        continue;</span><br><span class="line">                    &#125;</span><br><span class="line">                    break;</span><br><span class="line">                &#125; while (true);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">Affect(row-cnt:2) cost in 153 ms.</span><br></pre></td></tr></table></figure></p>
<h2 id="classloader"><a href="#classloader" class="headerlink" title="classloader"></a>classloader</h2><p>查看加载类继承树、urls、类加载信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$ classloader</span><br><span class="line"> name                                       numberOfInstances  loadedCountTotal</span><br><span class="line"> BootstrapClassLoader                       1                  1461</span><br><span class="line"> com.taobao.arthas.agent.ArthasClassloader  1                  1034</span><br><span class="line"> sun.misc.Launcher$AppClassLoader           1                  40</span><br><span class="line"> sun.reflect.DelegatingClassLoader          5                  5</span><br><span class="line"> sun.misc.Launcher$ExtClassLoader           1                  4</span><br><span class="line">Affect(row-cnt:5) cost in 3 ms.</span><br></pre></td></tr></table></figure></p>
<h2 id="redefine"><a href="#redefine" class="headerlink" title="redefine"></a>redefine</h2><p>加载外部的.class文件</p>
<p>==注意事项：== </p>
<ol>
<li><p>不允许新增加field/method</p>
</li>
<li><p>正在跑的函数，没有退出不能生效，比如下面新增加的System.out.println，只有run()函数里的会生效</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">public class MathGame &#123;</span><br><span class="line">    public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        MathGame game = new MathGame();</span><br><span class="line">        while (true) &#123;</span><br><span class="line">            game.run();</span><br><span class="line">            TimeUnit.SECONDS.sleep(1);</span><br><span class="line">            // 这个不生效，因为代码一直跑在 while里</span><br><span class="line">            System.out.println(&quot;in loop&quot;);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"> </span><br><span class="line">    public void run() throws InterruptedException &#123;</span><br><span class="line">        // 这个生效，因为run()函数每次都可以完整结束</span><br><span class="line">        System.out.println(&quot;call run()&quot;);</span><br><span class="line">        try &#123;</span><br><span class="line">            int number = random.nextInt();</span><br><span class="line">            List&lt;Integer&gt; primeFactors = primeFactors(number);</span><br><span class="line">            print(number, primeFactors);</span><br><span class="line"> </span><br><span class="line">        &#125; catch (Exception e) &#123;</span><br><span class="line">            System.out.println(String.format(&quot;illegalArgumentCount:%3d, &quot;, illegalArgumentCount) + e.getMessage());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h1 id="monitor"><a href="#monitor" class="headerlink" title="monitor"></a>monitor</h1><p>监控方法执行情况</p>
<p>示例代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">public class Test1 &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        Test1 test1 = new Test1();</span><br><span class="line">        while (true) &#123;</span><br><span class="line">            test1.test();</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String test() &#123;</span><br><span class="line">        System.out.println(&quot;test method execute&quot;);</span><br><span class="line">        return &quot;test method&quot;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>执行监控，默认是120s统计一次<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$ monitor com.boot.example.Test1</span><br><span class="line">The argument &apos;method-pattern&apos; is required</span><br><span class="line">$ monitor com.boot.example.Test1 test</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 49 ms.</span><br><span class="line"> timestamp            class                   method  total  success  fail  avg-rt(ms)  fail-rate</span><br><span class="line">--------------------------------------------------------------------------------------------------</span><br><span class="line"> 2018-12-11 13:17:03  com.boot.example.Test1  test    59     59       0     0.15        0.00%</span><br></pre></td></tr></table></figure></p>
<p>指定统计时间周期，5s统计一次<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">$ monitor -c 5 com.boot.example.Test1 test</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 25 ms.</span><br><span class="line"> timestamp            class                   method  total  success  fail  avg-rt(ms)  fail-rate</span><br><span class="line">--------------------------------------------------------------------------------------------------</span><br><span class="line"> 2018-12-11 13:20:55  com.boot.example.Test1  test    5      5        0     0.16        0.00%</span><br><span class="line"></span><br><span class="line"> timestamp            class                   method  total  success  fail  avg-rt(ms)  fail-rate</span><br><span class="line">--------------------------------------------------------------------------------------------------</span><br><span class="line"> 2018-12-11 13:21:00  com.boot.example.Test1  test    5      5        0     0.11        0.00%</span><br><span class="line"></span><br><span class="line"> timestamp            class                   method  total  success  fail  avg-rt(ms)  fail-rate</span><br><span class="line">--------------------------------------------------------------------------------------------------</span><br><span class="line"> 2018-12-11 13:21:05  com.boot.example.Test1  test    5      5        0     0.09        0.00%</span><br></pre></td></tr></table></figure></p>
<h2 id="watch"><a href="#watch" class="headerlink" title="watch"></a>watch</h2><p>观察方法执行情况</p>
<p>示例代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">public class Test1 &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        Test1 test1 = new Test1();</span><br><span class="line">        while (true) &#123;</span><br><span class="line">            test1.test(&quot;arthas watch&quot;);</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String test(String param) &#123;</span><br><span class="line">        System.out.println(&quot;【test method execute】，param：&quot; + param);</span><br><span class="line">        return &quot;test method&quot;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>观察方法出参和返回值<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">watch com.boot.example.Test1 test &#123;&quot;params,returnObj&quot;&#125; -x 2</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 50 ms.</span><br><span class="line">ts=2018-12-11 13:42:53; [cost=1.204007ms] result=@ArrayList[</span><br><span class="line">    @Object[][</span><br><span class="line">        @String[arthas watch],</span><br><span class="line">    ],</span><br><span class="line">    @String[test method],</span><br><span class="line">]</span><br><span class="line">ts=2018-12-11 13:42:54; [cost=0.167968ms] result=@ArrayList[</span><br><span class="line">    @Object[][</span><br><span class="line">        @String[arthas watch],</span><br><span class="line">    ],</span><br><span class="line">    @String[test method],</span><br><span class="line">]</span><br></pre></td></tr></table></figure></p>
<p>观察方法入参<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">watch com.boot.example.Test1 test &quot;&#123;params,returnObj&#125;&quot; -b -x 2</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 12 ms.</span><br><span class="line">ts=2018-12-11 13:43:41; [cost=0.024178ms] result=@ArrayList[</span><br><span class="line">    @Object[][</span><br><span class="line">        @String[arthas watch],</span><br><span class="line">    ],</span><br><span class="line">    null,</span><br><span class="line">]</span><br></pre></td></tr></table></figure></p>
<p>同时观察方法调用前和调用后情况<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">$ watch com.boot.example.Test1 test &quot;&#123;params,returnObj&#125;&quot; -b -s -n 2 -x 2</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 20 ms.</span><br><span class="line">ts=2018-12-11 13:47:52; [cost=0.025967ms] result=@ArrayList[</span><br><span class="line">    @Object[][</span><br><span class="line">        @String[arthas watch],</span><br><span class="line">    ],</span><br><span class="line">    null,</span><br><span class="line">]</span><br><span class="line">ts=2018-12-11 13:47:52; [cost=1.950267ms] result=@ArrayList[</span><br><span class="line">    @Object[][</span><br><span class="line">        @String[arthas watch],</span><br><span class="line">    ],</span><br><span class="line">    @String[test method],</span><br><span class="line">]</span><br><span class="line">Command execution times exceed limit: 2, so command will exit. You can set it with -n option.</span><br></pre></td></tr></table></figure></p>
<p>-n：代表执行的次数，示例中指定执行2次</p>
<p>输出的结果：</p>
<p>第一次输出的是方法调用前的结果</p>
<p>第二次输出的是方法调用返回后的结果</p>
<p>指定条件表达式，输出结果<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">$ watch com.boot.example.Test1 test1 &quot;&#123;params,target,returnObj&#125;&quot; &quot;params[0] &gt; 10&quot; -x 2</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 13 ms.</span><br><span class="line">ts=2018-12-11 14:00:02; [cost=0.133118ms] result=@ArrayList[</span><br><span class="line">    @Object[][</span><br><span class="line">        @Integer[89],</span><br><span class="line">    ],</span><br><span class="line">    @Test1[</span><br><span class="line">    ],</span><br><span class="line">    @Integer[7921],</span><br><span class="line">]</span><br><span class="line">ts=2018-12-11 14:00:03; [cost=0.069731ms] result=@ArrayList[</span><br><span class="line">    @Object[][</span><br><span class="line">        @Integer[64],</span><br><span class="line">    ],</span><br><span class="line">    @Test1[</span><br><span class="line">    ],</span><br><span class="line">    @Integer[4096],</span><br><span class="line">]</span><br></pre></td></tr></table></figure></p>
<p>只有异常的时候执行</p>
<p>示例代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">public class Test1 &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        Test1 test1 = new Test1();</span><br><span class="line">        while (true) &#123;</span><br><span class="line">            test1.test(&quot;arthas watch&quot;);</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">            try &#123;</span><br><span class="line">                test1.test1(new Random().nextInt(100));</span><br><span class="line">            &#125; catch (Exception e) &#123;</span><br><span class="line">                System.out.println(&quot;异常发生。。。。。。&quot;);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String test(String param) &#123;</span><br><span class="line">        System.out.println(&quot;【test method execute】，param：&quot; + param);</span><br><span class="line">        return &quot;test method&quot;;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    public int test1(int param) &#123;</span><br><span class="line">        int sum = param * param;</span><br><span class="line">        if (sum &gt; 9000) &#123;</span><br><span class="line">            throw new RuntimeException(&quot;the number is too large&quot;);</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        return sum;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>执行命令<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">$ watch com.boot.example.Test1 test1 &quot;&#123;params,throwExp&#125;&quot; -e -x 2</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 13 ms.</span><br><span class="line">ts=2018-12-11 14:07:10; [cost=0.180398ms] result=@ArrayList[</span><br><span class="line">    @Object[][</span><br><span class="line">        @Integer[97],</span><br><span class="line">    ],</span><br><span class="line">    java.lang.RuntimeException: the number is too large</span><br><span class="line">	at com.boot.example.Test1.test1(Test1.java:35)</span><br><span class="line">	at com.boot.example.Test1.main(Test1.java:19)</span><br><span class="line">,</span><br><span class="line">]</span><br><span class="line">ts=2018-12-11 14:07:20; [cost=0.151122ms] result=@ArrayList[</span><br><span class="line">    @Object[][</span><br><span class="line">        @Integer[99],</span><br><span class="line">    ],</span><br><span class="line">    java.lang.RuntimeException: the number is too large</span><br><span class="line">	at com.boot.example.Test1.test1(Test1.java:35)</span><br><span class="line">	at com.boot.example.Test1.main(Test1.java:19)</span><br><span class="line">,</span><br><span class="line">]</span><br></pre></td></tr></table></figure></p>
<p>根据耗时过滤</p>
<p>示例代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">public class Test1 &#123;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        Test1 test1 = new Test1();</span><br><span class="line">        while (true) &#123;</span><br><span class="line">            test1.test(&quot;arthas watch&quot;);</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">            try &#123;</span><br><span class="line">                test1.test1(new Random().nextInt(100));</span><br><span class="line">            &#125; catch (Exception e) &#123;</span><br><span class="line">                System.out.println(&quot;异常发生。。。。。。&quot;);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String test(String param) &#123;</span><br><span class="line">        System.out.println(&quot;【test method execute】，param：&quot; + param);</span><br><span class="line">        return &quot;test method&quot;;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    public int test1(int param) throws InterruptedException &#123;</span><br><span class="line">        int sum = param * param;</span><br><span class="line">        if (sum &gt; 9000) &#123;</span><br><span class="line">            throw new RuntimeException(&quot;the number is too large&quot;);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        if (sum &gt; 5000) &#123;</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        return sum;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>只有耗时大于200ms才执行<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">$ watch com.boot.example.Test1 test1 &quot;&#123;params,returnObj&#125;&quot; &quot;#cost&gt;200&quot; -x 2</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 45 ms.</span><br><span class="line">ts=2018-12-11 14:12:03; [cost=1004.969177ms] result=@ArrayList[</span><br><span class="line">    @Object[][</span><br><span class="line">        @Integer[87],</span><br><span class="line">    ],</span><br><span class="line">    @Integer[7569],</span><br><span class="line">]</span><br><span class="line">ts=2018-12-11 14:12:06; [cost=1003.329968ms] result=@ArrayList[</span><br><span class="line">    @Object[][</span><br><span class="line">        @Integer[88],</span><br><span class="line">    ],</span><br><span class="line">    @Integer[7744],</span><br><span class="line">]</span><br></pre></td></tr></table></figure></p>
<p>观察当前对象的属性</p>
<p>示例代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">public class Test1 &#123;</span><br><span class="line"></span><br><span class="line">    public int num = 0;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        Test1 test1 = new Test1();</span><br><span class="line">        while (true) &#123;</span><br><span class="line">            test1.test(&quot;arthas watch&quot;);</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">            try &#123;</span><br><span class="line">                test1.num = test1.test1(new Random().nextInt(100));</span><br><span class="line">            &#125; catch (Exception e) &#123;</span><br><span class="line">                System.out.println(&quot;异常发生。。。。。。&quot;);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String test(String param) &#123;</span><br><span class="line">        System.out.println(&quot;【test method execute】，param：&quot; + param);</span><br><span class="line">        return &quot;test method&quot;;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    public int test1(int param) throws InterruptedException &#123;</span><br><span class="line">        int sum = param * param;</span><br><span class="line">        if (sum &gt; 9000) &#123;</span><br><span class="line">            throw new RuntimeException(&quot;the number is too large&quot;);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        if (sum &gt; 5000) &#123;</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        return sum;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>输出当前对象的num属性</p>
<p>==注意点：== 该属性不能为private<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">$ watch com.boot.example.Test1 test1 &quot;target.num&quot;</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 50 ms.</span><br><span class="line">ts=2018-12-11 14:20:12; [cost=1006.227847ms] result=@Integer[1369]</span><br><span class="line">ts=2018-12-11 14:20:13; [cost=0.060729ms] result=@Integer[5329]</span><br><span class="line">ts=2018-12-11 14:20:14; [cost=0.061785ms] result=@Integer[2809]</span><br></pre></td></tr></table></figure></p>
<h2 id="trace"><a href="#trace" class="headerlink" title="trace"></a>trace</h2><p>方法内部调用路径，并输出方法路径每个节点耗时</p>
<p>示例代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">public class Test1 &#123;</span><br><span class="line"></span><br><span class="line">    public int num = 0;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) throws InterruptedException &#123;</span><br><span class="line">        Test1 test1 = new Test1();</span><br><span class="line">        while (true) &#123;</span><br><span class="line">            test1.test(&quot;arthas watch&quot;);</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">            try &#123;</span><br><span class="line">                test1.num = test1.test1(new Random().nextInt(100));</span><br><span class="line">            &#125; catch (Exception e) &#123;</span><br><span class="line">                System.out.println(&quot;异常发生。。。。。。&quot;);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String test(String param) &#123;</span><br><span class="line">        System.out.println(&quot;【test method execute】，param：&quot; + param);</span><br><span class="line">        return &quot;test method&quot;;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    public int test1(int param) throws InterruptedException &#123;</span><br><span class="line">        int sum = param * param;</span><br><span class="line">        if (sum &gt; 9000) &#123;</span><br><span class="line">            throw new RuntimeException(&quot;the number is too large&quot;);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        if (sum &gt; 5000) &#123;</span><br><span class="line">            Thread.sleep(1000);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        test2(sum);</span><br><span class="line">        return sum;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void test2(int param) throws InterruptedException &#123;</span><br><span class="line">        if (param &gt; 6000) &#123;</span><br><span class="line">            Thread.sleep(500);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>打印调用路径<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">$ trace com.boot.example.Test1 test1</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 60 ms.</span><br><span class="line">`---ts=2018-12-11 14:30:50;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">    `---[0.44977ms] com.boot.example.Test1:test1()</span><br><span class="line">        `---[0.019805ms] com.boot.example.Test1:test2()</span><br><span class="line"></span><br><span class="line">`---ts=2018-12-11 14:30:51;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">    `---[0.102314ms] com.boot.example.Test1:test1()</span><br><span class="line">        `---[0.009319ms] com.boot.example.Test1:test2()</span><br><span class="line"></span><br><span class="line">`---ts=2018-12-11 14:30:52;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">    `---[0.136561ms] com.boot.example.Test1:test1()</span><br><span class="line">        `---[0.008769ms] com.boot.example.Test1:test2()</span><br></pre></td></tr></table></figure></p>
<p>打印耗时超过1200ms的调用路径，并过滤掉jdk方法<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">$ trace -j com.boot.example.Test1 test1 &apos;#cost&gt;1200&apos;</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 14 ms.</span><br><span class="line">`---ts=2018-12-11 14:33:07;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">    `---[1508.110799ms] com.boot.example.Test1:test1()</span><br><span class="line">        `---[502.662704ms] com.boot.example.Test1:test2()</span><br><span class="line"></span><br><span class="line">`---ts=2018-12-11 14:33:13;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">    `---[1507.409364ms] com.boot.example.Test1:test1()</span><br><span class="line">        `---[505.206075ms] com.boot.example.Test1:test2()</span><br><span class="line"></span><br><span class="line">`---ts=2018-12-11 14:33:15;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">    `---[1505.490204ms] com.boot.example.Test1:test1()</span><br><span class="line">        `---[505.176712ms] com.boot.example.Test1:test2()</span><br></pre></td></tr></table></figure></p>
<p>-j：过滤掉jdk方法</p>
<p>#cost &gt; 1200：筛选出耗时大于1200的调用路径</p>
<h2 id="stack"><a href="#stack" class="headerlink" title="stack"></a>stack</h2><p>输出当前方法被调用的调用路径</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">$ stack com.boot.example.Test1 test2</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 28 ms.</span><br><span class="line">ts=2018-12-11 14:36:40;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2</span><br><span class="line">    @com.boot.example.Test1.test1()</span><br><span class="line">        at com.boot.example.Test1.main(Test1.java:21)</span><br></pre></td></tr></table></figure>
<h2 id="tt"><a href="#tt" class="headerlink" title="tt"></a>tt</h2><p>时间隧道，记录现场，还原现场，模拟现场</p>
<p>记录现场执行情况<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">$ tt -t com.boot.example.Test1 test2</span><br><span class="line">Press Ctrl+C to abort.</span><br><span class="line">Affect(class-cnt:1 , method-cnt:1) cost in 13 ms.</span><br><span class="line"> INDEX    TIMESTAMP               COST(ms)   IS-RET    IS-EXP   OBJECT            CLASS                              METHOD</span><br><span class="line">-------------------------------------------------------------------------------------------------------------------------------------------------------</span><br><span class="line"> 1000     2018-12-11 14:42:08     0.263585   true      false    0x1efbd816        Test1                              test2</span><br><span class="line"> 1001     2018-12-11 14:42:09     0.049794   true      false    0x1efbd816        Test1                              test2</span><br><span class="line"> 1002     2018-12-11 14:42:10     0.046289   true      false    0x1efbd816        Test1                              test2</span><br><span class="line"> 1003     2018-12-11 14:42:11     0.046195   true      false    0x1efbd816        Test1                              test2</span><br></pre></td></tr></table></figure></p>
<p>还原现场<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ tt -l</span><br><span class="line"> INDEX    TIMESTAMP               COST(ms)   IS-RET    IS-EXP   OBJECT            CLASS                              METHOD</span><br><span class="line">-------------------------------------------------------------------------------------------------------------------------------------------------------</span><br><span class="line"> 1000     2018-12-11 14:42:08     0.263585   true      false    0x1efbd816        Test1                              test2</span><br><span class="line"> 1001     2018-12-11 14:42:09     0.049794   true      false    0x1efbd816        Test1                              test2</span><br><span class="line"> 1002     2018-12-11 14:42:10     0.046289   true      false    0x1efbd816        Test1                              test2</span><br><span class="line"> 1003     2018-12-11 14:42:11     0.046195   true      false    0x1efbd816        Test1                              test2</span><br></pre></td></tr></table></figure></p>
<p>查看某个时间片的详细信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">$ tt -i 1000</span><br><span class="line"> INDEX          1000</span><br><span class="line"> GMT-CREATE     2018-12-11 14:42:08</span><br><span class="line"> COST(ms)       0.263585</span><br><span class="line"> OBJECT         0x1efbd816</span><br><span class="line"> CLASS          com.boot.example.Test1</span><br><span class="line"> METHOD         test2</span><br><span class="line"> IS-RETURN      true</span><br><span class="line"> IS-EXCEPTION   false</span><br><span class="line"> PARAMETERS[0]  @Integer[324]</span><br><span class="line"> RETURN-OBJ     null</span><br><span class="line">Affect(row-cnt:1) cost in 4 ms.</span><br></pre></td></tr></table></figure></p>
<p>tt -i index：index为时间片</p>
<p>重放现场<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">$ tt -i 1000 -p</span><br><span class="line"> RE-INDEX       1000</span><br><span class="line"> GMT-REPLAY     2018-12-11 14:52:26</span><br><span class="line"> OBJECT         0x1efbd816</span><br><span class="line"> CLASS          com.boot.example.Test1</span><br><span class="line"> METHOD         test2</span><br><span class="line"> PARAMETERS[0]  @Integer[324]</span><br><span class="line"> IS-RETURN      true</span><br><span class="line"> IS-EXCEPTION   false</span><br><span class="line"> RETURN-OBJ     null</span><br><span class="line">Time fragment[1000] successfully replayed.</span><br><span class="line">Affect(row-cnt:1) cost in 4 ms.</span><br></pre></td></tr></table></figure></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Arthas/" rel="tag"># Arthas</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/12/11/Arthas入门教程/Arthas入门教程/" rel="next" title="Arthas入门教程">
                <i class="fa fa-chevron-left"></i> Arthas入门教程
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/12/12/Spring-Boot验证国际化/Spring-Boot验证国际化/" rel="prev" title="Spring Boot验证国际化">
                Spring Boot验证国际化 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Wolf、Heart</p>
              <p class="site-description motion-element" itemprop="description">主要用于分享平时学习的只是以及遇到的困难，帮助自己以及需要的人一起共同成长</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">45</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">14</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#Arthas进阶使用，介绍每个命令的详细使用方法"><span class="nav-number">1.</span> <span class="nav-text">Arthas进阶使用，介绍每个命令的详细使用方法</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#一、基础命令"><span class="nav-number"></span> <span class="nav-text">一、基础命令</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#二、jvm相关"><span class="nav-number"></span> <span class="nav-text">二、jvm相关</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#dashboard"><span class="nav-number"></span> <span class="nav-text">dashboard</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#thread"><span class="nav-number"></span> <span class="nav-text">thread</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jvm"><span class="nav-number"></span> <span class="nav-text">jvm</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#sysprop"><span class="nav-number"></span> <span class="nav-text">sysprop</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#sysenv"><span class="nav-number"></span> <span class="nav-text">sysenv</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#getstatic"><span class="nav-number"></span> <span class="nav-text">getstatic</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ognl"><span class="nav-number"></span> <span class="nav-text">ognl</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#sc"><span class="nav-number"></span> <span class="nav-text">sc</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#sc-1"><span class="nav-number"></span> <span class="nav-text">sc</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dump"><span class="nav-number"></span> <span class="nav-text">dump</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jad"><span class="nav-number"></span> <span class="nav-text">jad</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#classloader"><span class="nav-number"></span> <span class="nav-text">classloader</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#redefine"><span class="nav-number"></span> <span class="nav-text">redefine</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#monitor"><span class="nav-number"></span> <span class="nav-text">monitor</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#watch"><span class="nav-number"></span> <span class="nav-text">watch</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#trace"><span class="nav-number"></span> <span class="nav-text">trace</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#stack"><span class="nav-number"></span> <span class="nav-text">stack</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#tt"><span class="nav-number"></span> <span class="nav-text">tt</span></a></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Wolf、Heart</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
